package com.briup.es.web.controller;

import com.briup.es.config.response.Result;
import com.briup.es.domain.vo.CollectVO;
import com.briup.es.service.CollectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import java.util.List;

@Api(tags = "收藏管理模块")
@RestController
@RequestMapping("/collect")
public class CollectController {

    @Resource
    private CollectService collectService;

    @ApiOperation("获取用户的所有收藏信息")
    @GetMapping
    public Result<?> queryAll() {
        List<CollectVO> collectVOS = collectService.queryAll();
        return Result.success(collectVOS)
                .apply("获取成功");
    }

    @ApiOperation("取消收藏")
    @DeleteMapping
    public Result<?> cancelCollect(
            @NotEmpty(message = "图书id不能为空")
            @RequestBody List<Integer> ids) {
        collectService.cancelCollectBatch(ids);
        return Result.success();
    }

    @ApiOperation("添加收藏")
    @PostMapping("/{bookId}")
    public Result<?> addCollect(@PathVariable Integer bookId) {
        collectService.addCollect(bookId);
        return Result.success();
    }
}
